#include <stdio.h>
#include <assert.h>
#include "thread.h"

#define ITE 1000000000
#define PRINT_MODULO (ITE/10)

void * thfunc(void * dummy)
{
  int i,j;
 int id = *((int *) dummy);
 for(i=0; i<ITE; i++)
    {
      if((i%PRINT_MODULO)==0)
	{
	  for(j=0;j<id;j++){
	    printf("           ");
	  }
	  printf("(Thread %d)\n",id);
	}
    }
 printf("(Fin Thread %d)\n", id);
}

int main()
{
  thread_t th, th2;
  int err;
  int a =1;
  int b =2;
  err = thread_create(&th, thfunc, &a);
  assert(!err);
  thread_priority(th,-20);
  err = thread_create(&th2, thfunc, &b);
  assert(!err);
  thread_priority(th2,20);
 
  int i;
  for(i=0; i<ITE; i++)
    {
      if((i%PRINT_MODULO)==0)
	printf("(main)\n");
    }
  printf("(Fin main)\n");
  thread_join(th, NULL);
  thread_join(th2, NULL);
  printf("\n");
  return 0;
}
